"""
    姓名 :  新  哥
    时间 : 2022/6/29 上午 09:53
    文件名 : test03_recharge.py
    需求：
    
"""
import allure
import pytest
import requests

from API.recharge_api import RechargeApi
from API.reg_login_api import RegLoginApi
from common.utils import common_assert, html_util, read_json


@allure.feature("开户接口")
class TestRecharge(object):
    """充值接口测试用例"""
    def setup(self):
        session = requests.session()
        self.recharge_api = RechargeApi(session)
        self.reg_login_api = RegLoginApi(session)

    @allure.story("充值图片验证码")
    @pytest.mark.parametrize("r,exp_status_code,desc",read_json("recharge_data","recharge_verify_code"))
    def test01_recharge_verify(self,r,exp_status_code,desc):
        allure.dynamic.title(desc)
        resp = self.recharge_api.recharge_verify(r)
        assert exp_status_code == resp.status_code

    @allure.story("充值")
    @pytest.mark.parametrize("desc,money,code,exp_status_code,exp_status,exp_description",read_json("recharge_data","recharge"))
    def test02_recharge(self,desc,money,code,exp_status_code,exp_status,exp_description):
        allure.dynamic.title(desc)
        self.reg_login_api.user_login("13419876880","qqq123")
        self.recharge_api.recharge_verify(123456)
        resp = self.recharge_api.recharge(money,code)
        common_assert(resp,exp_status_code,exp_status,exp_description)

    @allure.story("第三方开户")
    @allure.title("第三方充值成功")
    def test03_third_open_recharge(self):

        self.reg_login_api.user_login("13419876880", "qqq123")
        self.recharge_api.recharge_verify(123456)
        recharge = self.recharge_api.recharge(100000, 8888)
        data_list = html_util(recharge)
        url = data_list[0]
        form_dict = data_list[1]
        resp = self.recharge_api.third_open_recharge(url,form_dict)
        assert 200 == resp.status_code
        assert "OK" in resp.text
